package com.hunan.yllxy.util;

import com.hunan.yllxy.exceptions.CustomerException;
import org.springframework.lang.Nullable;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: 刘华
 * @Date: 2024/3/1 0001 9:57
 * @Version 1.0
 */
public class Preconditions {

    public static void checkArgument(boolean expression, @Nullable Object errorMessage) {
        if (!expression) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }

    public static void checkNullArgument(String str, @Nullable Object errorMessage) {
        if (StringUtils.isNull(str)) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }

    public static void checkNullArgument(MultipartFile multipartFile, @Nullable Object errorMessage) {
        if (multipartFile==null) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }

    public static void checkNullArgument(Object object, @Nullable Object errorMessage) {
        if (object==null) {
//            CustomerException customerException = new CustomerException();
//            customerException.setMess();
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }
    public static void checkNullArgument(List lists, @Nullable Object errorMessage) {
        if (StringUtils.isNull(lists)) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }


    public static void checkNullArgument(Boolean b, @Nullable Object errorMessage) {
        if (b==null) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }

    public static void checkNullArgument(Integer i, @Nullable Object errorMessage) {
        if (i==null) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }
    public static void checkNullArgument(Long l, @Nullable Object errorMessage) {
        if (l==null) {
            throw new CustomerException(String.valueOf(errorMessage)+"不能为空");
        }
    }
}
